from flask import request
from SQLOperation.PatientSQLOperation import Patient, PatientSQLOperation
from SQLConfig import app
from updateProjectFile import changeProjectFile


@app.route('/newPatient', methods=['Get', 'POST'])
def newPatient():  # put application's code here
    """
    新建患者
    """
    name = request.json.get("name")
    gender = request.json.get("gender")
    age = request.json.get("age")
    time = request.json.get("time")
    phone = request.json.get("phone")
    username = request.json.get("username")
    return newp(name, gender, age, time, phone, username)

def newp(name, gender, age, time, phone, username):
    n = PatientSQLOperation.insert(name, gender, age, time, phone, username)
    if n == 0:
        return "patient exist"
    else:
        changeProjectFile(n, "patientInformation", "init", 0, {
            "id": n,
            "name": name,
            "gender": gender,
            "age": age,
            "time": time,
            "phone": phone,
            "username": username
        })
        return str(n)